fn extract_number_and_base(input: &str) -> (String, u32) {
    let parts: Vec<&str> = input.split('(').collect();
    if parts.len() != 2 {
        panic!("Input format error. Expected format: number(base)");
    }

    let number = parts[0].trim();
    let base_str = parts[1].trim_end_matches(')');

    // 转换进制部分为数字
    let base = base_str.parse::<u32>().unwrap_or_else(|_| {
        panic!("Invalid base value: {}", base_str);
    });

    // 返回数字部分和进制
    (number.to_string(), base)
}

fn get_char(digit_value: u32) -> char {
    return if digit_value < 10 {
        (digit_value as u8 + b'0') as char
    } else {
        (digit_value as u8 - 10 + b'a') as char
    };
}

fn get_num(digit: char) -> u32 {
    return if digit.is_digit(10) {
        digit.to_digit(10).unwrap()
    } else {
        digit.to_ascii_uppercase() as u32 - 'A' as u32 + 10
    };
}
pub fn convert_base(num_str: &str, to_base: u32) -> String {
    let (x, y) = extract_number_and_base(num_str);
    let mut tm_d = 0u32;

    for c in x.chars() {
        tm_d = tm_d * y + get_num(c);
    }
    let mut ans = String::from("");
    if tm_d == 0 {
        ans.push('0');
    }
    while tm_d > 0 {
        ans.push(get_char(tm_d % to_base));
        tm_d /= to_base;
    }
    return ans.chars().rev().collect();
}
